package com.guigu.dealservice.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.guigu.dealservice.dto.Equipment;
import com.guigu.dealservice.dto.EquipmentImage;
import com.guigu.dealservice.dto.User;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 订单表（存储买卖双方的交易订单信息）
 * </p>
 *
 * @author ysp
 * @since 2025-10-10
 */
@TableName("`order`")
public class Order implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 订单唯一标识
     */
    @TableId(value = "order_id", type = IdType.AUTO)
    private Long orderId;

    /**
     * 关联用户表user_id（买家）
     */
    private Long buyerId;

    /**
     * 关联用户表user_id（卖家）
     */
    private Long sellerId;

    /**
     * 关联设备表equipment_id（唯一，一个设备同一时间仅一个有效订单）
     */
    private Long equipmentId;

    /**
     * 订单总金额（单位：元，设备成交价格）
     */
    private BigDecimal orderAmount;

    /**
     * 定金金额（订单总金额的30%，用于锁定设备）
     */
    private BigDecimal depositAmount;

    /**
     * 尾款金额（订单总金额-定金金额）
     */
    private BigDecimal balanceAmount;

    /**
     * 定金支付时间（买家支付定金的时间）
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime depositPayTime;

    /**
     * 尾款支付时间（买家支付尾款的时间）
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime balancePayTime;

    /**
     * 订单状态（0-待支付定金，1-已支付定金，2-待支付尾款，3-已支付尾款，4-已发货，5-已收货，6-已完成，7-已取消）
     */
    private Integer orderStatus;

    /**
     * 支付方式（微信支付、支付宝支付、银行卡支付等）
     */
    private String paymentMethod;

    /**
     * 物流公司（订单状态=4时必填，如顺丰、德邦）
     */
    private String logisticsCompany;

    /**
     * 物流单号（订单状态=4时必填，用于查询物流进度）
     */
    private String logisticsNo;

    /**
     * 确认收货时间（订单状态=5时必填，买家点击确认收货的时间）
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime receiptTime;

    /**
     * 评价时间（订单状态=6时必填，买家提交评价的时间）
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime evaluationTime;

    /**
     * 记录创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    /**
     * 记录更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;
    /**
     * 买家设备检测状态（0-无需检测，1-需要检测，2-检测完成，也就是添加报告成功）
     */
    private  Integer inspectionStatus;
    public Integer getInspectionStatus() {
        return inspectionStatus;
    }
    public void setInspectionStatus( Integer  inspectionStatus) {
        this.inspectionStatus = inspectionStatus;
    }
    //用户表
    @TableField(exist = false)
    private User user;
    //设备表
    @TableField(exist = false)
    private List<Equipment> equipment;
    //设备图片表
    @TableField(exist = false)
    private List<EquipmentImage> equipmentImages;

    @TableField(exist = false)
    private Equipment equipmentOne;
    //映射设备对象
    @TableField(exist = false)
    private Equipment  equipmentdx;
    @TableField(exist = false)
    private User buyerUser;
    @TableField(exist = false)
    private User sellerUser;

    public Equipment getEquipmentdx() {
        return equipmentdx;
    }

    public void setEquipmentdx( Equipment  equipmentdx) {
        this.equipmentdx = equipmentdx;
    }

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public Long getBuyerId() {
        return buyerId;
    }

    public void setBuyerId(Long buyerId) {
        this.buyerId = buyerId;
    }

    public Long getSellerId() {
        return sellerId;
    }

    public void setSellerId(Long sellerId) {
        this.sellerId = sellerId;
    }

    public Long getEquipmentId() {
        return equipmentId;
    }

    public void setEquipmentId(Long equipmentId) {
        this.equipmentId = equipmentId;
    }

    public BigDecimal getOrderAmount() {
        return orderAmount;
    }

    public void setOrderAmount(BigDecimal orderAmount) {
        this.orderAmount = orderAmount;
    }

    public BigDecimal getDepositAmount() {
        return depositAmount;
    }

    public void setDepositAmount(BigDecimal depositAmount) {
        this.depositAmount = depositAmount;
    }

    public BigDecimal getBalanceAmount() {
        return balanceAmount;
    }

    public void setBalanceAmount(BigDecimal balanceAmount) {
        this.balanceAmount = balanceAmount;
    }

    public LocalDateTime getDepositPayTime() {
        return depositPayTime;
    }

    public void setDepositPayTime(LocalDateTime depositPayTime) {
        this.depositPayTime = depositPayTime;
    }

    public LocalDateTime getBalancePayTime() {
        return balancePayTime;
    }

    public void setBalancePayTime(LocalDateTime balancePayTime) {
        this.balancePayTime = balancePayTime;
    }

    public Integer getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(Integer orderStatus) {
        this.orderStatus = orderStatus;
    }

    public String getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(String paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public String getLogisticsCompany() {
        return logisticsCompany;
    }

    public void setLogisticsCompany(String logisticsCompany) {
        this.logisticsCompany = logisticsCompany;
    }

    public String getLogisticsNo() {
        return logisticsNo;
    }

    public void setLogisticsNo(String logisticsNo) {
        this.logisticsNo = logisticsNo;
    }

    public LocalDateTime getReceiptTime() {
        return receiptTime;
    }

    public void setReceiptTime(LocalDateTime receiptTime) {
        this.receiptTime = receiptTime;
    }

    public LocalDateTime getEvaluationTime() {
        return evaluationTime;
    }

    public void setEvaluationTime(LocalDateTime evaluationTime) {
        this.evaluationTime = evaluationTime;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Equipment> getEquipment() {
        return equipment;
    }

    public void setEquipment(List<Equipment> equipment) {
        this.equipment = equipment;
    }

    public List<EquipmentImage> getEquipmentImages() {
        return equipmentImages;
    }

    public void setEquipmentImages(List<EquipmentImage> equipmentImages) {
        this.equipmentImages = equipmentImages;
    }

    public Equipment getEquipmentOne() {
        return equipmentOne;
    }

    public void setEquipmentOne(Equipment equipmentOne) {
        this.equipmentOne = equipmentOne;
    }

    public User getBuyerUser() {
        return buyerUser;
    }

    public void setBuyerUser(User buyerUser) {
        this.buyerUser = buyerUser;
    }

    public User getSellerUser() {
        return sellerUser;
    }

    public void setSellerUser(User sellerUser) {
        this.sellerUser = sellerUser;
    }
    @Override
    public String toString() {
        return "Order{" +
        "orderId = " + orderId +
        ", buyerId = " + buyerId +
        ", sellerId = " + sellerId +
        ", equipmentId = " + equipmentId +
        ", orderAmount = " + orderAmount +
        ", depositAmount = " + depositAmount +
        ", balanceAmount = " + balanceAmount +
        ", depositPayTime = " + depositPayTime +
        ", balancePayTime = " + balancePayTime +
        ", orderStatus = " + orderStatus +
        ", paymentMethod = " + paymentMethod +
        ", logisticsCompany = " + logisticsCompany +
        ", logisticsNo = " + logisticsNo +
        ", receiptTime = " + receiptTime +
        ", evaluationTime = " + evaluationTime +
        ", createTime = " + createTime +
        ", updateTime = " + updateTime +
         ", equipmentdx = " + equipmentdx +
         "equipment = " + equipment +
         "equipmentImages = " + equipmentImages +
         "equipmentOne = " + equipmentOne +
         "inspectionStatus = " + inspectionStatus +
         "buyerUser = " + buyerUser +
         "sellerUser = " + sellerUser +
        "}";
    }
}
